﻿

    (function () {
        var authorForm = {
            
            
       
           
            Init: function (config) {
              
                this.containerF = config.containerForm;
                this.href = config.href;
                this.twt = config.twt;
                this.url = config.url;
                this.setUrl();
                this.hideForm();
                this.submitF();
                this.GetName();
               
            },
            setUrl: function () {
              
                $('a#tweets').attr('href', this.url)
                

            },
            hideForm: function () {
                var $this=this;
                
                $('#t').on('click', function () {
                    $($this.containerF).toggle(300);
                
                    //console.log('bbk')
                });
            },
            submitF: function () {
                var $this = this;
                
                //console.log($this)
                $("#btn_Ajax").on('click', function (index) {
                    debugger;
                    var temp=  {
                        UserName: $("#Login").val(),
                        PassWord: $("#InputPassword").val(),
                        ConfirmPassWord: $("#ConfirmInputPassword").val(),
                        Roles: $("#takero option:selected").val(),
                        Mail: $('#exampleInputEmail1').val(),
                    }
                    //console.log(temp);
               
                   
                    $.ajax({
                        url: '/Account/RegisterAuthor',
                        data:JSON.stringify(temp),
                        type: 'POST',
                        contentType: 'application/json; charset=utf-8',
                        success: function (data) {
                            var output;
                            console.log('hi there')


                        }
                    });
                    
                    //$.post("/Test/RegisterAuthor", temp, function (result) {
                    //    console.log(result);
                    //});
                });
            },
          
            GetName: function () {
                var $this = this;
                $.ajax({
                    url: '/Account/GetAuthorNames',
                    type: 'get',
                    dataType: 'json',
                    cache: false,
                    success: function (data) {
                     
                        var auth= {   
                            authorname: data.results.Name,
                            authorlastname: data.results.Lastname
                        };
                        $('<em>' + auth.authorname + ' ' + auth.authorlastname + '</em>', {

                        }).insertAfter('.glyphicon');
             
                        $this.twt.mouseenter(function () {
               

             
                            if ($(document).find('span.cop').length) return;
                 
                            $('<span class=cop>Déconnexion </span>')
                                .animate({
                                    width: ["toggle", "swing"],
                                    height: ["toggle", "swing"],
                                    opacity: "toggle"
                                }, 5000)
                                .insertAfter($this.twt);

                            $('span.cop').toggle(3000);

                        });

             
                    }
                });
            }
        }



        authorForm.Init({
            containerForm: $("#formaduser"),
            href : $('a#tweets').attr('href'),
            twt: $("#tweets"),
            url:"/Account/Login"
        });
    })();

